<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			/* 用window.onload来让页面加载完成之后才执行js */
			window.onload = function(){
				var but = document.getElementById("but");
				but.onclick = function(){
					alert("别点！");
				}
			}
		</script>
	</head>
	<body>
		<button id="but">按钮</button>
		<!-- 将js代码编写到标签下才可执行-->
		<!-- <script>
			var but = document.getElementById("but");
			but.onclick = function(){
				alert("别点！");
			}
		</script> -->
	</body>
</html>
